using DG.Tweening;
using System;
using UnityEngine;
using UnityEngine.UI;

public class UI_MainMenu : MonoBehaviour
{
	public Button _Btn_开始游戏;

	public Button _Btn_重新开始;

	public Button _Btn_调戏休整;

    public Button _Btn_点赞;

	public Button _Btn_投币;

	public Button _Btn_收藏;

	public CanvasGroup _CG_三连成功文本提示;

	public AudioClip _AudioC_UI_三连;

	public Animator _Ani_Btn;

	public Slider _Slider_音乐;

	public Slider _Slider_音效;

    public GameObject privacypanel;

    public Button _Btn_隐私政策;

    public Button _Btn_更多精彩;

    public Button _Btn_添加桌面;

    public Button _Btn_退出游戏;

    private void Start()
	{
        AdManager.Instance.AddBtn(_Btn_隐私政策.gameObject, _Btn_更多精彩.gameObject, _Btn_退出游戏.gameObject, _Btn_添加桌面.gameObject);
        _Btn_隐私政策.onClick.AddListener(delegate
        {
            AdManager.Instance.Hide(privacypanel);
        });
        _Btn_更多精彩.onClick.AddListener(delegate
        {
            AdManager.Instance.MoreGame();
        });
        _Btn_添加桌面.onClick.AddListener(delegate
        {
            AdManager.Instance.AddDesktopIcon();
        });
        _Btn_退出游戏.onClick.AddListener(delegate
        {
            AdManager.Instance.Quit();
        });
        if (AdManager.IsOpenWorkTimeShield)
		{
            _Btn_调戏休整.gameObject.SetActive(false);
			_Slider_音乐.gameObject.SetActive(false);
			_Slider_音效.gameObject.SetActive(false);
        }
        _Slider_音乐.onValueChanged.AddListener(delegate(float val)
		{
			MonoSingleton<AudioManager>.Instance._AudioS_BGM.volume = val;
		});
		_Slider_音效.onValueChanged.AddListener(delegate(float val)
		{
			MonoSingleton<AudioManager>.Instance._AudioS_UISFX.volume = val;
			MonoSingleton<AudioManager>.Instance._AudioS_SFX.volume = val;
		});
		_Slider_音乐.value = PlayerPrefs.GetFloat("_Slider_音乐", 1f);
		_Slider_音效.value = PlayerPrefs.GetFloat("_Slider_音效", 1f);
		GameManager._开启时间积累 = false;
		_Btn_开始游戏.onClick.AddListener(delegate
		{
            Action action = () =>
            {
                Debug.LogError("开始游戏");
                MonoSingleton<GameManager>.Instance.F_直面天命();
                MonoSingleton<AudioManager>.Instance.F_Play_UI_点击();
            };
            if (AdManager.Instance.ShieldAddress) action();
            else CheckTouch.Show(action);
        });
		_Btn_重新开始.onClick.AddListener(delegate
		{
            Action action = () =>
            {
                Debug.LogError("开始游戏");
                MonoSingleton<GameManager>.Instance.F_重新开始();
                MonoSingleton<AudioManager>.Instance.F_Play_UI_点击();
            };
            if (AdManager.Instance.ShieldAddress) action();
            else CheckTouch.Show(action);
        });
		_Btn_调戏休整.onClick.AddListener(delegate
		{
			MonoSingleton<AudioManager>.Instance.F_Play_UI_点击();
			_Ani_Btn.SetTrigger("切换调息休整");
			PlayerPrefs.SetFloat("_Slider_音乐", _Slider_音乐.value);
			PlayerPrefs.SetFloat("_Slider_音效", _Slider_音效.value);
			PlayerPrefs.Save();
		});
		_Btn_点赞.onClick.AddListener(delegate
		{
			F_三连();
		});
		_Btn_投币.onClick.AddListener(delegate
		{
			F_三连();
		});
		_Btn_收藏.onClick.AddListener(delegate
		{
			Application.OpenURL("https://www.bilibili.com/video/BV1WQxee4Eyv");
		});
		MonoSingleton<AudioManager>.Instance.F_Play_BGM(MonoSingleton<AudioManager>.Instance._AudioC_云宫迅音);
		Debug.LogError("GameManager._已三连<<" + GameManager._已三连);
		if (GameManager._已三连 != 1.2f)
		{
			_CG_三连成功文本提示.alpha = 0f;
		}
	}

	private void F_三连()
	{
		Debug.LogError("GameManager._已三连<<" + GameManager._已三连);
		if (GameManager._已三连 != 1.2f)
		{
			MonoSingleton<AudioManager>.Instance.F_Play_UISFX(_AudioC_UI_三连);
			GameManager._已三连 = 1.2f;
			Image 点赞 = _Btn_点赞.transform.GetChild(0).GetComponent<Image>();
			Image 投币 = _Btn_投币.transform.GetChild(0).GetComponent<Image>();
			Image 收藏 = _Btn_收藏.transform.GetChild(0).GetComponent<Image>();
			点赞.DOFillAmount(1f, 1f).SetEase(Ease.Linear);
			投币.DOFillAmount(1f, 1f).SetEase(Ease.Linear);
			收藏.DOFillAmount(1f, 1f).SetEase(Ease.Linear).OnComplete(delegate
			{
				点赞.DOFade(0f, 0.5f);
				投币.DOFade(0f, 0.5f);
				收藏.DOFade(0f, 0.5f);
				_CG_三连成功文本提示.DOFade(1f, 0.5f);
			});
		}
	}

	private void OnDestroy()
	{
		GameManager._开启时间积累 = true;
		MonoSingleton<AudioManager>.Instance.F_Play_BGM(MonoSingleton<AudioManager>.Instance._AudioC_黑神话_悟空_BGM);
	}
}
